package com.cjjd.c.feature.home.chekin.select_detail;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cjjd.c.R;
import com.cjjd.c.bean.CheckInDetailBean;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * ----------------------------------
 * Created by xyd on 2017/8/30.
 * <p/>
 * 描  述：
 * <p/>
 * 修订历史:
 * ----------------------------------
 */

public class SelectExpandableLisetAdapter extends BaseExpandableListAdapter {

    private ArrayList<String> dataI;
    private ArrayList<ArrayList<CheckInDetailBean.HotelFloor.HotelItemFloorItem>> dataG;
    private Context mContext;

    public SelectExpandableLisetAdapter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public int getGroupCount() {
        return dataI.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return dataG.get(groupPosition).size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return dataI.get(groupPosition);
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return dataG.get(groupPosition).get(childPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {

        ViewHolderGroup viewHolderGroup = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_account_check_group, parent, false);
            viewHolderGroup = new ViewHolderGroup(convertView);
            convertView.setTag(viewHolderGroup);
        } else {
            viewHolderGroup = (ViewHolderGroup) convertView.getTag();
        }


        viewHolderGroup.tvElistviewTittle.setText(dataI.get(groupPosition));

        return convertView;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        ViewHolderChild viewHolderChild = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_account_check_child, parent, false);
            viewHolderChild = new ViewHolderChild(convertView);
            convertView.setTag(viewHolderChild);
        } else {
            viewHolderChild = (ViewHolderChild) convertView.getTag();
        }
        return convertView;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }


    public void setGroupData(ArrayList<ArrayList<CheckInDetailBean.HotelFloor.HotelItemFloorItem>> listG) {
        this.dataG = listG;
    }

    public void setItemData(ArrayList<String> listI) {
        this.dataI = listI;
    }

    static class ViewHolderGroup {
        @Bind(R.id.tv_elistview_tittle)
        TextView tvElistviewTittle;
        @Bind(R.id.tv_elistview_content)
        TextView tvElistviewContent;
        @Bind(R.id.tv_consume)
        TextView tvConsume;
        @Bind(R.id.ll_consum_with_arrow)
        LinearLayout llConsumWithArrow;

        ViewHolderGroup(View view) {
            ButterKnife.bind(this, view);
        }
    }

    static class ViewHolderChild {
        @Bind(R.id.tv_child_tittle)
        TextView tvChildTittle;
        @Bind(R.id.tv_child_content)
        TextView tvChildContent;
        @Bind(R.id.ev_consume)
        TextView evConsume;

        ViewHolderChild(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
